#define history list
history_list = [
    {'date':'03.03.2020', 'operation':'new account', 'amount':0,},
]
user_list = [
    {'username':'coco','password':'cococo'}
]
balance = 1000

#check balance
def show_balance():
    print('|{0:<5}|{1:<11}|{2:<12}|{3:<12}|{4:<12}'.format('id','date','operation','amount','balance'))
    print('-'*80)
    for i,history in enumerate(history_list):
        print('|{0:<5}|{1:<11}|{2:<12}|{3:<10}|{4:<12}'.format(i+1,history['date'],history['operation'],history['amount'],balance))
#show_balance()

#add operation history
def add_operation(date, operation, amount):
    global balance
    history= {}
    history['date']= date
    history['operation'] = operation
    history['amount']= amount
    print(history)
    history_list.append(history)
    if operation == 'save':
        balance = balance + int(amount)
        print('Succeed! Your current balance is:', balance)
        main()
    elif operation == 'deposit':
        balance = balance - int(amount)
        print('Succeed! Your current balance is:', balance)
        main()
    elif operation != 'save' and operation !='deposit':
        print('ERROR!!!')

#login system
def home_page():
    print('Welcome to ATM!')
    print('$'*60)
    info1 = input('Your account:')
    info2 = input('Your password:')
    print('$'*60)
    for i in range(len(user_list)):
        if info1 == user_list[i]['username'] and info2 == user_list[i]['password']:
            main()
        else:
            print('Wrong username/password!')
            home_page()

#main
def main():
    print('Please choose your operation:')
    operation1= input('1.check balance history 2. save  3.deposit  4. exit')
    if operation1 == '1':
        show_balance()
        main()
    elif operation1 == '2':
        date1 = input('today is:')
        amount1= input('choose amount:')
        add_operation(date1, 'save', amount1)
        main()
    elif operation1 =='3':
        date1 = input('today is:')
        amount1 = input('choose amount:')
        add_operation(date1, 'deposit', amount1)
        main()
    elif operation1 =='4':
        print('Thanks for using, bye!')
        exit()
home_page()